/*  
  -- The Lime II Project -- 

  A tuplespaces-based middleware for coordinating agents and mobile hosts.
  Copyright (C) 2005.
  Gian Pietro Picco, Amy L. Murphy, Lorenzo Bellini.

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  Lesser General Public License for more details.

  You should have received this copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
 */

package sagroup.dracots.testing;

import java.util.HashMap;

import lime2.Location;
import sagroup.dracots.DracoTS;
import sagroup.dracots.TupleType;
import sagroup.dracots.policy.ReplicationPolicy;

/**
 * A simple agent
 * 
 * @author Huang Xiaodong
 */

public class DisplayPolicyRegistrar implements Runnable {
	/*
	 * Get the Hash map of Replica policy 
	 */
	HashMap<TupleType, HashMap<Location, ReplicationPolicy>> policyMap;
	
	/**
	 * Constructor method (default). Destination location is here.
	 */
	public DisplayPolicyRegistrar() {
	}

	/**
	 * Run method.
	 */
	public void run() {
		System.out.println("Started");
		try {
			// Here to get a DracoTupleSpace instance named testing.
			DracoTS dts = DracoTS.get("testing");
			Thread.sleep(35000);
			policyMap = dts.getPolicyRegistrar().getAllReplicaPolicy();
			
			System.out.println("Show the contents of replicaRegistra.");
			for (TupleType type : policyMap.keySet()) {
				System.out.println("Type = " + type + " ,");
				HashMap<Location, ReplicationPolicy> inner = policyMap.get(type);
				if (inner != null) {
					for (Location loc : inner.keySet())
						System.out.println("   Location = " + loc
								+ " and Replication Policy = " + inner.get(loc));
				}
			}
			
		} catch (Exception e) {
			System.out.println("Operation failed!");
			e.printStackTrace();
		}
		System.out.println("Done!");
	}
}